<extend name="./public/frame.html"/>
<block name="content">
	<blockquote class="layui-elem-quote search">
		<div class="layui-inline">
			<select name="province_id" id="province_id" class="layui-input" lay-filter="province" style="width: 150px;" onclick="getProvinceList();">
				<option value="">请选择省份</option>
				<option value="0">默认省份</option>
				<?php foreach($provinceList as $key=>$value):?>
				<option value="<?php echo $value['region_id'];?>"><?php echo $value['region_name'];?></option>
				<?php endforeach;?>
			</select>
		</div>
		<div class="layui-inline">
			<select name="city_id" id="city_id" class="layui-input" lay-filter="city_id" style="width: 150px;">
				<option value="">请选择城市</option>
			</select>
		</div>
		<div class="layui-inline">
			<button class="layui-btn" data-type="search">搜索</button>
			<button class="layui-btn layui-btn-normal" data-url="{:url('add')}" onclick="add_t(this,'添加城市')">
				添加城市
			</button>
		</div>
	</blockquote>
	<table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{:url('CostConfig/index')}', page: true, limit: 10, id:'CostConfig'}" lay-filter="CostConfig">
		<thead>
		<tr>
			<th lay-data="{field:'id', width:70,fixed: true, sort: true,align:'center',fixed: true}">ID</th>
			<th lay-data="{field:'province_name', width:100,align:'center'}">省份名称</th>
			<th lay-data="{field:'city_name', width:100,align:'center'}">城市名称</th>
			<th lay-data="{field:'first_name', width:60,align:'center'}">字母</th>
			<th lay-data="{field:'start_mileage', width:120,align:'center'}">起步里程(KM)</th>
			<th lay-data="{field:'start_time', width:110,align:'center'}">起步时长(分)</th>
			<th lay-data="{field:'start_fee', width:100,align:'center'}">起步价(元)</th>
			<th lay-data="{field:'mileage_fee', width:120,align:'center'}">里程费(元/分)</th>
			<th lay-data="{field:'time_fee', width:120,align:'center'}">时长费(元/分)</th>
			<th lay-data="{field:'over_wait_fee', width:140,align:'center'}">超时等待费(元/分)</th>
			<th lay-data="{field:'plate_fee', width:100,align:'center'}">手续费(%)</th>
			<th lay-data="{field:'is_user', width:120,templet: '#Tpl',align:'center'}">营运状态</th>
			<th lay-data="{field:'is_valuation', width:120,templet: '#TplDefin',align:'center'}">计价规则</th>
			<th lay-data="{field:'is_cancel', width:120,templet: '#TplSuburb',align:'center'}">取消扣费规则</th>
			<th lay-data="{field:'remote_order', width:120,templet: '#Tpremote',align:'center'}">异地接单</th>
			<th lay-data="{fixed:'right', toolbar: '#barDemo', width:150, align:'center'}">操作</th>
		</tr>
		</thead>
	</table>
	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs" lay-event="edit" style="width: 50px">修改</a>
		<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="look" style="width: 50px">查看</a>
	</script>
	<script type="text/html" id="Tpl">
		<input type="checkbox" name="is_use" data-id="{{d.id}}" value="{{d.is_use}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="is_user" {{ d.is_use == 1 ? 'checked' : '' }}>
	</script>
	<script type="text/html" id="TplDefin">
		<input type="checkbox" name="is_valuation" data-id="{{d.id}}" value="{{d.is_valuation}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="is_valuation" {{ d.is_valuation == 1 ? 'checked' : '' }}>
	</script>
	<script type="text/html" id="TplSuburb">
		<input type="checkbox" name="is_cancel" data-id="{{d.id}}" value="{{d.is_cancel}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="is_cancel" {{ d.is_cancel == 1 ? 'checked' : '' }}>
	</script>
	<script type="text/html" id="Tpremote">
		<input type="checkbox" name="is_cancel" data-id="{{d.id}}" value="{{d.remote_order}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="remote_order" {{ d.remote_order == 1 ? 'checked' : '' }}>
	</script>
	<script>
		layui.use(['form','table'], function () {
			var table = layui.table,form = layui.form;
			table.on('tool(CostConfig)', function (obj) {
				var data = obj.data;
				var id = data.id;
				if (obj.event === 'edit') {
					layer.open({
						type: 2,
						title: '编辑信息',
						shadeClose: true,
						shade: 0.8,
						area: ['100%', '100%'],
						content: '{:url("/admin/CostConfig/edit","id=")}' + id //iframe的url
					});
				}else if (obj.event === 'look') {
					layer.open({
						type: 2,
						title: '查看计价信息',
						shadeClose: true,
						shade: 0.8,
						area: ['100%', '100%'],
						content: '{:url("/admin/CostConfig/look","id=")}' + id //iframe的url
					});
				}
			});
			//搜索
			$('.layui-btn').on('click', function () {
				var provinceId 	= $("#province_id").val();
				var cityId 		= $("#city_id").val();
				table.reload('CostConfig', {
					url: '/admin/CostConfig/index', where: {
						"provinceId": provinceId,
						"cityId": cityId,
					}
				});
			});
			var url = "{:url('is_open')}";
			//城市运营状态
			form.on('switch(is_user)', function(obj){
				var ori = obj.elem.checked == true ? false : true;//在没有操作前加载的复选框属性值
				var id = obj.elem.dataset.id;
				var tip = ori == true ? '确定关闭么?' : '确定开启么?';
				var value = ori == true ? 0 : 1;
				layer.confirm(tip, {icon: 3, title: '提示'},	function (index) {
					$.post(url, {'id': id,'value':value,'type':1}, function (data) {
						if(data.status == 1){
							layer.msg(data.msg,{'icon':1});
						}else{
							layer.msg(data.msg,{'icon':2});
						}
					}, 'json');
					layer.close(index);
				})
			});
			//取消订单扣费规则
			form.on('switch(is_cancel)', function(obj){
				var ori = obj.elem.checked == true ? false : true;//在没有操作前加载的复选框属性值
				var id = obj.elem.dataset.id;
				var tip = ori == true ? '确定关闭么?' : '确定开启么?';
				var value = ori == true ? 0 : 1;
				layer.confirm(tip, {icon: 3, title: '提示'},	function (index) {
					$.post(url, {'id': id,'value':value,'type':2}, function (data) {
						if(data.status == 1){
							layer.msg(data.msg,{'icon':1});
						}else{
							layer.msg(data.msg,{'icon':2});
						}
					}, 'json');
					layer.close(index);
				})
			});

			//计价规则
			form.on('switch(is_valuation)', function(obj){
				var ori = obj.elem.checked == true ? false : true;//在没有操作前加载的复选框属性值
				var id = obj.elem.dataset.id;
				var tip = ori == true ? '确定关闭么?' : '确定开启么?';
				var value = ori == true ? 0 : 1;
				layer.confirm(tip, {icon: 3, title: '提示'},	function (index) {
					$.post(url, {'id': id,'value':value,'type':3}, function (data) {
						if(data.status == 1){
							layer.msg(data.msg,{'icon':1});
						}else{
							layer.msg(data.msg,{'icon':2});
						}
					}, 'json');
					layer.close(index);
				})
			});
			//异地选值
			form.on('switch(remote_order)', function(obj){
				var ori = obj.elem.checked == true ? false : true;//在没有操作前加载的复选框属性值
				var id = obj.elem.dataset.id;
				var tip = ori == true ? '确定关闭么?' : '确定开启么?';
				var value = ori == true ? 0 : 1;
				layer.confirm(tip, {icon: 3, title: '提示'},	function (index) {
					$.post(url, {'id': id,'value':value,'type':5}, function (data) {
						if(data.status == 1){
							layer.msg(data.msg,{'icon':1});
						}else{
							layer.msg(data.msg,{'icon':2});
						}
					}, 'json');
					layer.close(index);
				})
			});
		});

		//城市
		function getProvinceList(){
			var province_id = $("#province_id").val();
			if(province_id == 0){
				$("#city_id").empty();
				$("#city_id").append('<option value=>请选择城市</option>');
				$("#city_id").append('<option value=0>默认城市</option>');
				return false;
			}
			$("#city_id").empty();
			$("#city_id").append('<option value=>请选择城市</option>');
			$.ajax({
				url:'{:url("/admin/Franchisee/cityList")}',
				async:true,
				//dataType:'json',
				type:'post',
				data:{'province_id':province_id},
				success:function(res){
					$("#city_id").append(res);
				},
				error:function(e){
					layer.msg('请求错误');return false;
				}
			})
		};
	</script>
</block>
